package com.archives.blog.run;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.archives.blog.common.interceptor.ERPAdminSecurityInterceptor;
import com.archives.blog.common.interceptor.ThymeleafLayoutInterceptor;

@ComponentScan("com.archives.blog.*")
@EntityScan("com.archives.blog.common.domain.entity*")
@SpringBootApplication
@EnableAutoConfiguration
@EnableScheduling
@EnableJpaRepositories("com.archives.blog.common.domain.dao")
public class Application extends WebMvcConfigurerAdapter{
	
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
	
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
	
	@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        super.addResourceHandlers(registry);
    }
	
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new ThymeleafLayoutInterceptor()).addPathPatterns("/**");
		registry.addInterceptor(new ERPAdminSecurityInterceptor()).addPathPatterns("/erp/**").excludePathPatterns("/erp/login");
	}
}
